package com.fjl.prediction.pojo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@TableName("sys_user")
public class SysUser implements UserDetails {

    @TableId
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    private String username;

    private String password;

    private String realname;

    private String sex;

    private Date birthday;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long departmentId;

    private String email;

    private String phone;

    private Integer enable;

    @TableField("create_time")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long createTime;


    @TableField(exist = false)
    private List<SysRole> roles = new ArrayList<>();

    @TableField(exist = false)
    private List<SysMenu> authorities = new ArrayList<>();


    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return null!=enable && enable == 1;
    }


}


